home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWODUtil / Include / FWSUBuff.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  4.0 KB  |  141 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:        FWSUBuff.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSUBUFF_H
  11. #define FWSUBUFF_H
  12.  
  13. #ifndef FWEXCDEF_H
  14. #include "FWExcDef.h"
  15. #endif
  16.  
  17. #if FW_LIB_EXPORT_PRAGMAS
  18. #pragma lib_export on
  19. #endif
  20.  
  21. //========================================================================================
  22. //    class FW_CStorageUnitBuffer
  23. //
  24. //  This class implements a buffer for use with FW_CStorageUnitSink.  Each call to
  25. //    FW_CStorageUnitSink::Read() results in the creation and destruction of an
  26. //    intermediate FW_CByteArray.  To eliminate some of the expense associated with
  27. //    that operation, ReadPeek() and WritePeek() methods of FW_CStorageUnitSink use
  28. //    this class to allow the buffering of data being read and/or written to/from
  29. //    a storage unit.
  30. //
  31. //    Note that none of the methods of this class actually do any reading or writing.
  32. //    The FW_CStorageUnitSink instance must obtain a pointer to the buffer in memory
  33. //    and fill it with data.  This class is responsible only for maintaining the
  34. //    buffer and data pertaining directly to it.
  35. //
  36. //    This is an implementation class, and it should be considered private to
  37. //    FW_CStorageUnitSink.
  38. //========================================================================================
  39.  
  40. class FW_CLASS_ATTR FW_CStorageUnitBuffer FW_AUTO_DESTRUCT_OBJECT
  41. {
  42. public:
  43.  
  44.     enum {
  45.         kDefaultCapacity = 1024
  46.     };
  47.     
  48.     enum EBufferKind {
  49.         kInvalid,
  50.         kReadPeek,
  51.         kWritePeek
  52.     };
  53.     
  54.     // ----- Constructors, destructor, operators -----
  55.  
  56.     FW_CStorageUnitBuffer(long fCapacity = kDefaultCapacity);
  57.     FW_CStorageUnitBuffer(const FW_CStorageUnitBuffer& otherBuffer);
  58.     
  59.     ~FW_CStorageUnitBuffer();
  60.     
  61.     FW_CStorageUnitBuffer& operator=(const FW_CStorageUnitBuffer&);
  62.     
  63.     // ----- Getters & setters -----
  64.  
  65.     char*        GetAddress();
  66.     long        GetCapacity();
  67.     long        GetPosition();
  68.     long        GetInitialPosition();
  69.     FW_Boolean     IsDirty();
  70.     
  71.     // ----- Buffer-management routines -----
  72.  
  73.     void         Initialize(EBufferKind kind, long validBytes = 0, long filePosition = 0);
  74.  
  75.     const void* ReadPeek(long& availableReadBytes);
  76.     void         ReadPeekAdvance(long bytesRead);
  77.  
  78.     void*         WritePeek(long& availableWriteBytes);
  79.     void         WritePeekAdvance(long bytesWritten);
  80.  
  81. private:
  82.  
  83.     char* fBuffer;
  84.     long fCapacity;
  85.     long fValidBytes;
  86.     long fPosition;
  87.     long fType;
  88.     long fInitialPosition;
  89. };
  90.  
  91. //----------------------------------------------------------------------------------------
  92. //    FW_CStorageUnitBuffer::GetAddress
  93. //----------------------------------------------------------------------------------------
  94.  
  95. inline char* FW_CStorageUnitBuffer::GetAddress()
  96. {
  97.     return fBuffer;
  98. }
  99.  
  100. //----------------------------------------------------------------------------------------
  101. //    FW_CStorageUnitBuffer::GetCapacity
  102. //----------------------------------------------------------------------------------------
  103.  
  104. inline long FW_CStorageUnitBuffer::GetCapacity()
  105. {
  106.     return fCapacity;
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CStorageUnitBuffer::GetPosition
  111. //----------------------------------------------------------------------------------------
  112.  
  113. inline long FW_CStorageUnitBuffer::GetPosition()
  114. {
  115.     return fPosition;
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. //    FW_CStorageUnitBuffer::GetInitialPosition
  120. //----------------------------------------------------------------------------------------
  121.  
  122. inline long FW_CStorageUnitBuffer::GetInitialPosition()
  123. {
  124.     return fInitialPosition;
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    FW_CStorageUnitBuffer::IsDirty
  129. //----------------------------------------------------------------------------------------
  130.  
  131. inline FW_Boolean FW_CStorageUnitBuffer::IsDirty()
  132. {
  133.     return fType == kWritePeek && fPosition != 0;
  134. }
  135.  
  136. #if FW_LIB_EXPORT_PRAGMAS
  137. #pragma lib_export off
  138. #endif
  139.  
  140. #endif
  141.